(in-package #:experiment)

;;; methods to print/read SDL objects so they can be dumped and read
;;; back in from the save files.

(defmethod print-object ((obj sdl:ttf-font) stream)
  (let ((pn (parse-namestring (sdl::filename (sdl::font-definition obj)))))
    (format stream "#f(\"~a.~a\" ~s)"
            (pathname-name pn) (pathname-type pn)
            (sdl::char-size (sdl::font-definition obj)))))

(defmethod print-object ((obj sdl:color) stream)
  (format stream "#c(~a ~a ~a)"
          (sdl:r obj)
          (sdl:g obj)
          (sdl:b obj)))

(defun read-sdl-color (stream ch n)
  (declare (ignore ch n))
  (let ((list (read stream nil (values) t)))
    (when (consp list)
      (apply #'gwee:color list))))

(defun read-sdl-font (stream ch n)
  (declare (ignore ch n))
  (let ((list (read stream nil (values) t)))
    (when (consp list)
      (apply #'gwee:open-font list))))

;;; FIXME: we override the complex number reader.
(set-dispatch-macro-character #\# #\c #'read-sdl-color)
(set-dispatch-macro-character #\# #\f #'read-sdl-font)
